<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日期工具函数测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        h1 {
            color: #333;
            border-bottom: 2px solid #eee;
            padding-bottom: 10px;
        }
        h2 {
            color: #555;
            margin-top: 30px;
        }
        .test-section {
            margin-bottom: 30px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
        .test-case {
            margin-bottom: 10px;
            padding: 8px;
            border-left: 3px solid #4CAF50;
            background-color: #f1f1f1;
        }
        .test-case span {
            font-weight: bold;
            color: #333;
        }
        .result {
            color: #0066cc;
            font-family: monospace;
        }
        .error {
            color: #d9534f;
        }
        .note {
            color: #8a6d3b;
            font-style: italic;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <h1>企业级ERP系统日期工具函数测试</h1>
    <p>以下是对扩展后的日期工具函数的测试结果：</p>

    <div class="test-section">
        <h2>基础格式化函数</h2>
        <div class="test-case">
            <span>format_datetime:</span> <span class="result" id="format-datetime"></span>
        </div>
        <div class="test-case">
            <span>format_date:</span> <span class="result" id="format-date"></span>
        </div>
        <div class="test-case">
            <span>format_time:</span> <span class="result" id="format-time"></span>
        </div>
        <div class="test-case">
            <span>format_relative_time:</span> <span class="result" id="format-relative-time"></span>
        </div>
    </div>

    <div class="test-section">
        <h2>日期信息获取函数</h2>
        <div class="test-case">
            <span>get_weekday:</span> <span class="result" id="get-weekday"></span>
        </div>
        <div class="test-case">
            <span>get_weekday_short:</span> <span class="result" id="get-weekday-short"></span>
        </div>
        <div class="test-case">
            <span>get_month_chinese:</span> <span class="result" id="get-month-chinese"></span>
        </div>
        <div class="test-case">
            <span>get_quarter:</span> <span class="result" id="get-quarter"></span>
        </div>
        <div class="test-case">
            <span>get_quarter_chinese:</span> <span class="result" id="get-quarter-chinese"></span>
        </div>
    </div>

    <div class="test-section">
        <h2>日期判断函数</h2>
        <div class="test-case">
            <span>is_weekday:</span> <span class="result" id="is-weekday"></span>
        </div>
        <div class="test-case">
            <span>is_weekend:</span> <span class="result" id="is-weekend"></span>
        </div>
        <div class="test-case">
            <span>is_today:</span> <span class="result" id="is-today"></span>
        </div>
        <div class="test-case">
            <span>is_this_month:</span> <span class="result" id="is-this-month"></span>
        </div>
    </div>

    <div class="test-section">
        <h2>日期计算函数</h2>
        <div class="test-case">
            <span>get_days_between:</span> <span class="result" id="get-days-between"></span>
        </div>
        <div class="test-case">
            <span>get_weekdays_between:</span> <span class="result" id="get-weekdays-between"></span>
        </div>
        <div class="test-case">
            <span>add_weekdays:</span> <span class="result" id="add-weekdays"></span>
        </div>
        <div class="test-case">
            <span>format_duration:</span> <span class="result" id="format-duration"></span>
        </div>
    </div>

    <div class="test-section">
        <h2>日期范围函数</h2>
        <div class="test-case">
            <span>get_month_range:</span> <span class="result" id="get-month-range"></span>
        </div>
        <div class="test-case">
            <span>get_quarter_range:</span> <span class="result" id="get-quarter-range"></span>
        </div>
        <div class="test-case">
            <span>get_fiscal_year_start:</span> <span class="result" id="get-fiscal-year-start"></span>
        </div>
        <div class="test-case">
            <span>get_fiscal_year_end:</span> <span class="result" id="get-fiscal-year-end"></span>
        </div>
    </div>

    <div class="note">
        <p>注意：此测试页面仅用于演示日期工具函数的基本功能，实际使用时需要根据具体业务场景进行调整。</p>
        <p>部分函数（如节假日相关）需要额外的数据支持才能完全展示其功能。</p>
    </div>

    <script type="module">
        // 这里应该导入实际的日期工具函数
        // 由于无法直接导入TypeScript文件，这里使用模拟函数进行演示
        
        // 模拟当前日期
        const today = new Date();
        const testDate = new Date(2023, 5, 15); // 2023年6月15日
        
        // 模拟函数实现（简化版）
        function format_datetime(value, format = 'YYYY-MM-DD HH:mm:ss') {
            if (!value) return '';
            // 简化实现
            return value.toLocaleString('zh-CN');
        }
        
        function format_date(value) {
            if (!value) return '';
            return value.toLocaleDateString('zh-CN');
        }
        
        function format_time(value) {
            if (!value) return '';
            return value.toLocaleTimeString('zh-CN');
        }
        
        function format_relative_time(value) {
            if (!value) return '';
            // 简化实现
            return '2小时前';
        }
        
        function get_weekday(value) {
            if (!value) return '';
            const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
            return weekdays[value.getDay()];
        }
        
        function get_weekday_short(value) {
            if (!value) return '';
            const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
            return weekdays[value.getDay()];
        }
        
        function get_month_chinese(value) {
            if (!value) return '';
            const months = ['一月', '二月', '三月', '四月', '五月', '六月', 
                           '七月', '八月', '九月', '十月', '十一月', '十二月'];
            return months[value.getMonth()];
        }
        
        function get_quarter(value) {
            if (!value) return 0;
            return Math.floor(value.getMonth() / 3) + 1;
        }
        
        function get_quarter_chinese(value) {
            const quarter = get_quarter(value);
            return `第${quarter}季度`;
        }
        
        function is_weekday(value) {
            if (!value) return false;
            const day = value.getDay();
            return day >= 1 && day <= 5;
        }
        
        function is_weekend(value) {
            if (!value) return false;
            const day = value.getDay();
            return day === 0 || day === 6;
        }
        
        function is_today(value) {
            if (!value) return false;
            return value.toDateString() === today.toDateString();
        }
        
        function is_this_month(value) {
            if (!value) return false;
            return value.getMonth() === today.getMonth() && value.getFullYear() === today.getFullYear();
        }
        
        function get_days_between(startDate, endDate) {
            if (!startDate || !endDate) return 0;
            const diffTime = Math.abs(endDate - startDate);
            return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
        }
        
        function get_weekdays_between(startDate, endDate) {
            if (!startDate || !endDate) return 0;
            let count = 0;
            const current = new Date(startDate);
            const end = new Date(endDate);
            
            if (current > end) {
                return get_weekdays_between(endDate, startDate);
            }
            
            while (current <= end) {
                if (is_weekday(current)) {
                    count++;
                }
                current.setDate(current.getDate() + 1);
            }
            
            return count;
        }
        
        function add_weekdays(value, days) {
            if (!value) return new Date();
            const date = new Date(value);
            let remainingDays = Math.abs(days);
            const isAdding = days > 0;
            
            if (!isAdding) {
                // 简化实现，不实现减去工作日
                return date;
            }
            
            while (remainingDays > 0) {
                date.setDate(date.getDate() + 1);
                if (is_weekday(date)) {
                    remainingDays--;
                }
            }
            
            return date;
        }
        
        function format_duration(minutes) {
            if (!minutes || minutes <= 0) return '0分钟';
            
            const days = Math.floor(minutes / (24 * 60));
            const hours = Math.floor((minutes % (24 * 60)) / 60);
            const mins = minutes % 60;
            
            const parts = [];
            if (days > 0) parts.push(`${days}天`);
            if (hours > 0) parts.push(`${hours}小时`);
            if (mins > 0 || parts.length === 0) parts.push(`${mins}分钟`);
            
            return parts.join('');
        }
        
        function get_month_range(value) {
            if (!value) return { start: new Date(), end: new Date() };
            const date = new Date(value);
            const start = new Date(date.getFullYear(), date.getMonth(), 1);
            const end = new Date(date.getFullYear(), date.getMonth() + 1, 0);
            return { start, end };
        }
        
        function get_quarter_range(value) {
            if (!value) return { start: new Date(), end: new Date() };
            const date = new Date(value);
            const quarter = get_quarter(date);
            const year = date.getFullYear();
            
            const quarterStartMonth = (quarter - 1) * 3;
            const start = new Date(year, quarterStartMonth, 1);
            const end = new Date(year, quarterStartMonth + 3, 0);
            
            return { start, end };
        }
        
        function get_fiscal_year_start(currentDate) {
            const date = currentDate ? new Date(currentDate) : new Date();
            const year = date.getMonth() >= 3 ? date.getFullYear() : date.getFullYear() - 1;
            return new Date(year, 3, 1); // 4月1日
        }
        
        function get_fiscal_year_end(currentDate) {
            const date = currentDate ? new Date(currentDate) : new Date();
            const year = date.getMonth() >= 3 ? date.getFullYear() + 1 : date.getFullYear();
            return new Date(year, 2, 31); // 3月31日
        }
        
        // 测试并显示结果
        document.getElementById('format-datetime').textContent = format_datetime(testDate);
        document.getElementById('format-date').textContent = format_date(testDate);
        document.getElementById('format-time').textContent = format_time(testDate);
        document.getElementById('format-relative-time').textContent = format_relative_time(testDate);
        
        document.getElementById('get-weekday').textContent = get_weekday(testDate);
        document.getElementById('get-weekday-short').textContent = get_weekday_short(testDate);
        document.getElementById('get-month-chinese').textContent = get_month_chinese(testDate);
        document.getElementById('get-quarter').textContent = get_quarter(testDate);
        document.getElementById('get-quarter-chinese').textContent = get_quarter_chinese(testDate);
        
        document.getElementById('is-weekday').textContent = is_weekday(testDate);
        document.getElementById('is-weekend').textContent = is_weekend(testDate);
        document.getElementById('is-today').textContent = is_today(testDate);
        document.getElementById('is-this-month').textContent = is_this_month(testDate);
        
        const startDate = new Date(2023, 5, 1);
        const endDate = new Date(2023, 5, 30);
        document.getElementById('get-days-between').textContent = get_days_between(startDate, endDate);
        document.getElementById('get-weekdays-between').textContent = get_weekdays_between(startDate, endDate);
        document.getElementById('add-weekdays').textContent = format_date(add_weekdays(testDate, 5));
        document.getElementById('format-duration').textContent = format_duration(1250);
        
        const monthRange = get_month_range(testDate);
        document.getElementById('get-month-range').textContent = `${format_date(monthRange.start)} 至 ${format_date(monthRange.end)}`;
        
        const quarterRange = get_quarter_range(testDate);
        document.getElementById('get-quarter-range').textContent = `${format_date(quarterRange.start)} 至 ${format_date(quarterRange.end)}`;
        
        document.getElementById('get-fiscal-year-start').textContent = format_date(get_fiscal_year_start(testDate));
        document.getElementById('get-fiscal-year-end').textContent = format_date(get_fiscal_year_end(testDate));
    </script>
</body>
</html>